import { createRouter, createWebHistory } from "vue-router";
import { BasicLayout } from "@/layouts";

const routes = [
  {
    path: "/",
    component: BasicLayout,
    redirect: "/media",
    children: [
      {
        path: "/media",
        name: "Media",
        component: () => import(/* webpackChunkName: "Media" */ "@/views/media/index.vue"),
        meta: {
          title: "媒体数据分析平台"
        }
      },
      {
        path: "/test",
        name: "Test",
        component: () => import(/* webpackChunkName: "Test" */ "@/views/test/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login/index.vue"),
  },
  {
    path: "/mobile",
    name: "/Mobile",
    component: () => import("@/views/mobile/index.vue"),
  },
  {
    path: "/404",
    component: () => import("@/views/exception/404.vue"),
  },
  {
    path: "/:catchAll(.*)",
    redirect: "/404",
  },
];
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

export function setupRouter(app) {
  app.use(router);
}

export default router;
